package club.gskj.gulimall.product.web;

import club.gskj.gulimall.product.service.SkuInfoService;
import club.gskj.gulimall.product.vo.SkuItemVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.concurrent.ExecutionException;

/**
 * @ClassName ItemController
 * @Description TODO
 * @Author 康纳
 * @Date 2021-03-11
 */

/**
 * 商品详情页面控制器
 */
@Controller
public class ItemController {


    @Autowired
    private SkuInfoService skuInfoService;

    /***
     *  根据 skuId 查询详细信息并返回到 详情页面
     * @param skuId 商品id
     */
    @RequestMapping("/{skuId}.html")
    public String skuItem(@PathVariable("skuId") Long skuId, Model model) throws ExecutionException, InterruptedException {

        SkuItemVo skuItemVo = skuInfoService.item(skuId);

        model.addAttribute("item", skuItemVo);
        return "item";
    }
}
